using Android.Content.PM;
using AndroidX.Core.App;
using AndroidX.Core.Content;
using Avalonia;
using Avalonia.Android;
using Avalonia.ReactiveUI;

namespace KinonekoSoftware.Studio
{

    [Activity(
                 Theme = "@style/JuXiaoYou.NoActionBar",
                 Icon = "@mipmap/appicon",
                 RoundIcon = "@mipmap/appicon_round",
                 MainLauncher = true,
                 ConfigurationChanges = ConfigChanges.Orientation | ConfigChanges.ScreenSize | ConfigChanges.UiMode,
                 ScreenOrientation = ScreenOrientation.SensorLandscape)]
    public partial class MainActivity : AvaloniaMainActivity<App>
    {
        
        protected override void OnCreate(Bundle savedInstanceState)
        {
            if (ContextCompat.CheckSelfPermission(this, Android.Manifest.Permission.WriteExternalStorage) != Permission.Granted)
            {
                RequestCameraPermissions();
            }
            
            base.OnCreate(savedInstanceState);
        }

        public void RequestCameraPermissions()
        {
            //
            // 请求摄像头的权限
            ActivityCompat.RequestPermissions(this, new []
            {
                Android.Manifest.Permission.ReadExternalStorage,
                Android.Manifest.Permission.WriteExternalStorage,
            }, (int)Permission.Granted);
        }
        
        protected override AppBuilder CustomizeAppBuilder(AppBuilder builder)
        {
            return base.CustomizeAppBuilder(builder)
                       .WithInterFont()
                       .UseReactiveUI();
        }
    }
}